package com.xjrsoft.module.customerTwo.aiplm.t_aiplm_model.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.common.page.ConventPage;
import java.util.List;
import com.xjrsoft.common.utils.DataTransUtil;
import com.xjrsoft.common.result.Response;
import com.xjrsoft.core.tool.utils.BeanUtil;
import com.xjrsoft.module.base.service.IXjrBaseCodeRuleService;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_model.dto.TAiplmModelDto;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_model.dto.SaveTAiplmModelFormDataDto;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_model.vo.TAiplmModelVo;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_model.vo.TAiplmModelListVo;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_model.dto.TAiplmModelListDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;

import org.springframework.web.bind.annotation.*;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_model.entity.TAiplmModel;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_model.vo.TAiplmModelVo;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_model.service.ITAiplmModelService;

/**
 *  控制器
 *
 * @author dongxinhang
 * @since 2024-07-03
 */
@RestController
@AllArgsConstructor
@RequestMapping("/t_aiplm_model")
@Api(value = "模型管理", tags = "模型管理接口")
public class TAiplmModelController {


	private final ITAiplmModelService tAiplmModelService;

	private final IXjrBaseCodeRuleService codeRuleService;

	/**
	 * 详情 
	 */
	@GetMapping("/{id}")
	@ApiOperation(value = "详情", notes = "传入tAiplmModel")
	@SaCheckPermission(value = {"t_aiplm_model:view", "t_aiplm_model:modify"}, mode = SaMode.OR)
	public Response<TAiplmModelVo> getFormData(@PathVariable String id) {
		// 主表数据
		TAiplmModel tAiplmModel = tAiplmModelService.getById(id);
		TAiplmModelVo tAiplmModelVo = BeanUtil.copy(tAiplmModel, TAiplmModelVo.class);
		return Response.ok(tAiplmModelVo);
	}

	/**
	 * 自定义分页 
	 */
	@GetMapping
	@ApiOperation(value = "分页", notes = "传入tAiplmModel")
		public Response<PageOutput<TAiplmModelListVo>> getPageList(TAiplmModelListDto listDto) {
		IPage<TAiplmModel> page = tAiplmModelService.getPageList(listDto);
		List<TAiplmModelListVo> records = BeanUtil.copyList(page.getRecords(), TAiplmModelListVo.class);
			// 转换列表数据
		DataTransUtil.transListShowData(records);
		return Response.ok(ConventPage.getPageOutput(page.getTotal(), records));
	}

	/**
	 * 新增 
	 */
	@PostMapping
	@ApiOperation(value = "新增", notes = "传入tAiplmModel")
	@SaCheckPermission("t_aiplm_model:add")
	public Response save(@RequestBody SaveTAiplmModelFormDataDto formDto) {
		TAiplmModelDto tAiplmModelDto = formDto.getTAiplmModelDto();
		TAiplmModel tAiplmModel = BeanUtil.copy(tAiplmModelDto, TAiplmModel.class);
		boolean isSuccess = tAiplmModelService.addTAiplmModel(tAiplmModel);
		if (isSuccess) {
			codeRuleService.useEncode("AiplmModelNum");
		}
		return Response.status(isSuccess);
	}

	/**
	 * 修改 
	 */
	@PutMapping("/{id}")
	@ApiOperation(value = "修改", notes = "传入tAiplmModel")
	@SaCheckPermission("t_aiplm_model:modify")
	public Response update(@PathVariable String id, @RequestBody SaveTAiplmModelFormDataDto formDto) {
		TAiplmModelDto tAiplmModelDto = formDto.getTAiplmModelDto();
		TAiplmModel tAiplmModel = BeanUtil.copy(tAiplmModelDto, TAiplmModel.class);
		return Response.status(tAiplmModelService.updateTAiplmModel(id, tAiplmModel));
	}



	/**
	 * 删除 
	 */
	@DeleteMapping("/{ids}")
	@ApiOperation(value = "删除", notes = "传入ids")
	@SaCheckPermission(value = {"t_aiplm_model:batchDelete", "t_aiplm_model:delete"}, mode = SaMode.OR)
	public Response remove(@ApiParam(value = "主键集合", required = true) @PathVariable String ids) {
		return Response.status(tAiplmModelService.delete(ids));
	}


}
